from collections import defaultdict

n = int(input())#输入社保号的数量
id_cnts = defaultdict(int) #记录每个id出现的次数

for _ in range(n):
    id_cur = input().strip()#记录下当前输入的id
    id_cnts[id_cur] += 1 #给当前id出现的次数+1

sorted_id = sorted(id_cnts.items(),key = lambda x : x[0])
for id_cnts in sorted_id:
    print(id_cur,id_cnts)